package com.pronosticos.reportes.dao.impl;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import com.googlecode.genericdao.search.SearchResult;

/**
 * Adaptador para exponer interfaz List
 * @param <T>
 */
@SuppressWarnings("hiding")
public class SearchResultListWrapper<T> extends SearchResult<T> implements List<T> { 
	
	private static final long serialVersionUID = -4236045455763748370L;
	private SearchResult<T> wrapped;
    private int maxRecords;
    private int pages;
    private int currentPage;

    public SearchResultListWrapper(List<T> data) {
        this.wrapped = new SearchResult<T>();
        this.wrapped.setResult(data);
    }
    
    public SearchResultListWrapper(List<T> data, int maxRecords, int currentPage, int totalCount) {
        this.wrapped = new SearchResult<T>();
        this.wrapped.setResult(data);
        this.maxRecords = maxRecords;
        this.currentPage = currentPage;
        this.wrapped.setTotalCount(totalCount);
        pages = (int)Math.ceil(wrapped.getTotalCount()*(1.0) / maxRecords);
    }    
    
    public SearchResultListWrapper(SearchResult<T> wrapped, int maxRecords, int currentPage) {
        this.wrapped = wrapped;
        this.maxRecords = maxRecords;
        this.currentPage = currentPage;
        pages = (int)Math.ceil(wrapped.getTotalCount()*(1.0) / maxRecords);
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public int getMaxRecords() {
        return maxRecords;
    }

    public int getPages() {
        return pages;
    }

    @Override
    public List<T> getResult() {
        return wrapped.getResult();
    }

    public void setResult(List<T> results) {
        wrapped.setResult(results);
    }

    @Override
    public int getTotalCount() {
        return wrapped.getTotalCount();
    }

    @Override
    public void setTotalCount(int totalCount) {
        wrapped.setTotalCount(totalCount);
    }

    public int size() {
        return getResult().size();
    }

    public boolean isEmpty() {
        return getResult().isEmpty();
    }

    public boolean contains(Object o) {
        return getResult().contains(o);
    }

    public Iterator<T> iterator() {
        return getResult().iterator();
    }

    public Object[] toArray() {
        return getResult().toArray();
    }

    
	public <T> T[] toArray(T[] a) {
        return getResult().toArray(a);
    }

    public boolean add(T t) {
        return getResult().add(t);
    }

    public boolean remove(Object o) {
        return getResult().remove(o);
    }

    public boolean containsAll(Collection<?> c) {
        return getResult().containsAll(c);
    }

    public boolean addAll(Collection<? extends T> c) {
        return getResult().addAll(c);
    }

    public boolean addAll(int index, Collection<? extends T> c) {
        return getResult().addAll(index, c);
    }

    public boolean removeAll(Collection<?> c) {
        return getResult().removeAll(c);
    }

    public boolean retainAll(Collection<?> c) {
        return getResult().retainAll(c);
    }

    public void clear() {
        getResult().clear();
    }

    @Override
    public boolean equals(Object o) {
        return getResult().equals(o);
    }

    @Override
    public int hashCode() {
        return getResult().hashCode();
    }

    public T get(int index) {
        return getResult().get(index);
    }

    public T set(int index, T element) {
        return getResult().set(index, element);
    }

    public void add(int index, T element) {
        getResult().add(index, element);
    }

    public T remove(int index) {
        return getResult().remove(index);
    }

    public int indexOf(Object o) {
        return getResult().indexOf(o);
    }

    public int lastIndexOf(Object o) {
        return getResult().lastIndexOf(o);
    }

    public ListIterator<T> listIterator() {
        return getResult().listIterator();
    }

    public ListIterator<T> listIterator(int index) {
        return getResult().listIterator(index);
    }

    public List<T> subList(int fromIndex, int toIndex) {
        return getResult().subList(fromIndex, toIndex);
    }
}
